home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: What are the differences between structures and classes in C++ ?
- Date: Mon, 08 Apr 1996 15:44:54 -0400
- Organization: Datalytics, Inc
- Message-ID: <31696CB6.79C3@datalytics.com>
- References: <4k9cr3$fl9@arl-news-svc-5.compuserve.com>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: quoted-printable
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Philippe Verdy wrote:
- > =
-
- > marnold@netcom.com (Matt Arnold) s'=E9crit :
- > > Raghuveera Ravinutala <raghur> writes:
- > >
- > > ><jtbell@presby.edu (Jon Bell)> wrote :
- > > >>the only *formal* difference between a class and a
- > > >>struct is that by default, class members are private whereas struct
- > > >>members are public.
- > >[snip]
- > > In other words, structs *are* classes.
- > =
-
- > And so, the "class" keyword was not necessary to C++ !!! It is
- > for only an historical (and cultural) reason that classes in C
- > can be specified with the "class" keyword. Historically,
- > structs in first C++ beta versions did not allow for methods
- > and constructor (because classes complicated the C++ to C
- > conversion, and made compilation time and generated volume
- > of C source much bigger). However, the need of costructors
- > for PODS structs relaxed this rule, and structs gained all
- > the capabilities of classes, for clarity and simplicity !
- > =
-
-
- Historical significance in beta versions of C++ translators, =
-
- aside, the reason for the class keyword is to make private =
-
- access the default. It is a way to highlight that you should =
-
- hide as much as you can.
-
- > In most sources,
- > the public members are specified at the beginning of the class
- > definition so using "struct" instead of "class" avoids to
- > explicitly use the "public:" access modifier and saves 7
- > characters !!!
- > =
-
-
- While this is accurate, and indeed there is no significant =
-
- difference between structs and classes, I prefer to use class =
-
- and struct to indicate something more. class refers to =
-
- something that hides information and provides a strictly defined =
-
- interface. struct refers to something that makes no attempt to =
-
- hide its representation, though it may have ctors, dtors, and =
-
- other mfs.
-
- In other words, while I can declare protected and private access =
-
- sections in a struct, I don't. I leave structs entirely public, =
-
- preferring class for everything else. This clarifies my intent.
-
- -- =
-
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-